import random
import time

arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
       'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
       'I', 'J', 'K', 'L',
       'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ]


# 检测回文数函数
def check_str(ins: str):
    nsi = ins[::-1]
    if ins == nsi:
        print("回文检测成功，回文字符串：{}".format(ins))
    else:
        print("回文检测失败，非回文字符串：{}".format(ins))


def wait_input():
    while True:
        input_str = input("请输入要检测的字符串(quit退出)：")
        if input_str == 'quit':
            return
        else:
            check_str(input_str)


def ranom_huiwen_str():
    print("成功进入数据生成模块...")
    time.sleep(0.3)
    print("读取基础数据...")
    num = random.randint(3, 8)
    huiwen_list = []
    for i in range(num):
        temp_str = random.choices(arr, k=random.randint(4, 12))
        temp_str = ''.join(temp_str)
        huiwen_str = temp_str + temp_str[::-1]
        huiwen_list.append(huiwen_str)
    return huiwen_list


def main():
    while True:
        ins = input("1 输入检测 2 随机产生 q退出：")
        if ins == 'q':
            print("启动清理程序")
            time.sleep(0.3)
            break
        elif ins == '1':
            print("匹配用户交换模块...")
            time.sleep(0.3)
            print("成功匹配，启动中...")
            time.sleep(2)
            print("启动成功，正在载入交互菜单...")
            time.sleep(0.3)
            wait_input()
        elif ins == '2':
            print("匹配数据生成模块...")
            time.sleep(0.3)
            print("成功匹配，启动中...")
            time.sleep(1)
            print("启动成功，正在载入...")
            time.sleep(0.4)
            print(ranom_huiwen_str())
        else:
            print("输入指令有误，请重新输入")


if __name__ == "__main__":
    print("程序初始化...")
    time.sleep(1)
    print("分配内存空间...")
    time.sleep(1)
    print("程序载入成功...")
    main()
    print("检测并关闭子进程...")
    time.sleep(0.3)
    print("清理内存...")
    time.sleep(0.3)
    print("关闭主进程...")
    time.sleep(0.3)
